<html>
<body>

<a href="javascript:kangxihui_invoke('details',100,test_callback)" >invoke test</a>
<div id="content"></div>
<script>


function test_callback(path, data){
    document.getElementById("content").innerText="invoke success!<br/>from:" + path + "<br/>data:" + data;
}

//以下为兼容 android 和 iOS 的 js 回调方式
function kangxihui_invoke(path,jsonstr,callback){
    var wj=window.JavaInterface;
    if(wj){
        wj.kangxihui_invoke(path,jsonstr,kangxihui_regcb(callback));
        return;
    }
    var url = "http://localhost/"+path;
    url += "?c="+kangxihui_regcb(callback);
    url += "&d="+jsonstr;
    //$.get(url);
    window.location.href=url;
}

function kangxihui_callback(cb,path,data){
    if(!cb)return;
    var self=kangxihui_callback;
    if(!self.cbs)return;
    cb = self.cbs[cb];
    if(!cb)return;
    cb(path,data);
}

function kangxihui_regcb(func){
    if(!func)return "";
    if(!func.cbidx){
        var self=kangxihui_callback;
        if(!self.cbs)self.cbs={cnt:0};
        self=self.cbs;
        func.cbidx="cb"+(self.cnt++);
        self[func.cbidx]=func;
    }
    return func.cbidx;
}
</script>

</body>
</html>